package com.dengxiujun.simpletomcat.web.servlet;

import com.dengxiujun.simpletomcat.request.HttpRequest;
import com.dengxiujun.simpletomcat.response.HttpResponse;
import com.dengxiujun.simpletomcat.servlet.HttpServlet;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * <p></p>
 *
 * @author dengxiujun
 * @date 2021-04-26
 **/
public class FaviconServlet extends HttpServlet {

    private static byte[] data = null;

    @Override
    public void doGet(HttpRequest req, HttpResponse rep) throws IOException {
        if (data == null) {
            data = Files.readAllBytes(Paths.get("src/main/resources/favicon.ico"));
        }
        rep.write(data);
    }

    @Override
    public void doPost(HttpRequest req, HttpResponse rep) throws IOException {
        doGet(req, rep);
    }

}
